package com.xiaoran.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
public class FlowimitController {
    @GetMapping("/testA")
    public String test1() {
        return "---------------testA";
    }

    @GetMapping("/testB")
    public String test2(){
        log.info(Thread.currentThread().getName()+"\t"+".........testB");
        return "------------------testB";
    }
    @GetMapping("/testE")
    public String testD(){
        log.info("testE-----异常比列");
        //int age =10 /0;
        return "----------testD";
    }

    @GetMapping("/testHotkey")
    @SentinelResource(value = "testHotkey",blockHandler = "deal_testhotkey")
    public String testhotkey(@RequestParam(value = "p1",required = false)String p1,
                             @RequestParam(value = "p2" ,required = false) String p2){

        return "---------------testHoykey";
    }
    public String deal_testhotkey(String p1, String p2, BlockException exception){
        return "------------deal_testhotkey /(ㄒoㄒ)/~~";// 自定义的系统错误提示方法
    }
}
